<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('凭证显示')" />
	<th:block th:include="include :: voucher-css" />
</head>
<body class="page-voucher theme2">
      <div class="voucher_wrap">
        <form id="form-list"  th:object="${tSrhsPzto}">
            <input id="pztxh" name="pztxh" type="hidden" th:value="*{pztxh}"/> 
            <div class="voucher_top">
			      <div class="mark_wrap">
			      	<span class="txt">凭证字</span>
			        <span class="ui-combo-wrap" id="vch_mark" style="width: 98px;">
			        <input type="text" name="pzlb" class="input-txt" autocomplete="off" value="" readonly="readonly" style="cursor: default; width: 72px;" th:value="*{pzlb}"><i class="trigger"></i></span>
			        <span class="ui-combo-wrap"><input type="text" class="input-txt" id="pzbh" style="cursor: default; width: 42px;" th:value="*{pzbh}" readonly="readonly"><span class="btn-wrap" ><a class="btn-up"></a><a class="btn-down"></a></span></span><span class="txt">号</span>
			        <span class="txt">凭证日期</span>
			        <span class="ui-combo-wrap">
			            <input type="text" class="input-txt" id="pzrq" style="cursor: default; width: 92px;" th:value="*{pzrq}" readonly="readonly">
			        </span>
			      </div>
			      <div class="tit_wrap">
			        <h1 class="voucher_tit">记账凭证</h1>
			      </div>
			      <span class="attach_wrap">
			       	 附单据
			        <input type="text" class="ui-input" id="fjzs" style="cursor: default; width: 52px;" th:value="*{fjzs}"  readonly="readonly">
			       	  张
			      </span>
			</div> 
            <div class="col-sm-12 select-table voucher">
                <table id="bootstrap-table" ></table>
            </div>
			<div class="vch_ft">
			      <span class="dn" id="modifyTime">制单人：<span th:text="*{zd}"></span></span> 
			      <span class="fr f12 g6 dn" id="ldr_people">审核人：<span th:text="*{sh}"></span></span>
			      <span class="fr f12 g6 dn" id="ldr_people">状态：<span th:text="*{pzzt}"></span></span>
			</div>
        </form>
    </div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
			var prefix = ctx + "system/pzto";
			$(function() {
		        var options = {
	        		url: prefix + "/pztilist",
	        		queryParams : {
	                    'pztxh':$("#pztxh").val()
					},
			        showSearch: false,
			        showRefresh: false,
			        showToggle: false,
			        showColumns: false,
			        pagination: false,
			        detailView: true,
			        showFooter: true,
					onExpandRow : function(index, row, $detail) {
						initChildTable(index, row, $detail);
					},
		            columns: [{
						field : 'pztxh', 
						title : '序号',
						visible: false
					},{
						field : 'xh', 
						width:60,
						title : '序号',
		                footerFormatter:function (value) {
	   				        return '合计:';
	   				    }
					},{
						field : 'zy', 
						width:200,
						title : '摘要',
		                footerFormatter:function (value) {
	   				    	var sumJe = 0;
	   				        for (var i in value) {
	   				        	sumJe += parseFloat(value[i].jfje);
	   				        }
	   				        return DX(sumJe);
	   				    }
					},{
						field : 'kmmc', 
						title : '科目名称',
						align: 'center',
						width:200,
						formatter: function(value, row, index) {  
		                    return row.kmmc+'['+row.kmdm+']';
		                }
		                
					},
					{
						field : 'jfje', 
						// class:'col_credit',
						title : $.common.sprintf('<strong class="tit">借方金额</strong><div class="money_unit"> <span>亿</span> <span>千</span> <span>百</span> <span>十</span> <span>万</span> <span>千</span> <span>百</span> <span>十</span> <span>元</span> <span>角</span> <span class="last">分</span></div>'), 
	                    formatter: function(value, row, index) {  
	                        return '<div class="col_credit"><div class="cell_val credit_val">'+yantofan(row.jfje)+'</div></div>';
	                    },
	   				    footerFormatter:function (value) {
	   				    	var sumJe = 0;
	   				        for (var i in value) {
	   				        	sumJe += parseFloat(value[i].jfje);
	   				        }
	   				        return '<div class="col_credit"> <div class="cell_val credit_val">'+yantofan(sumJe)+'</div></div>'
	   				    }
					},
					{
	                    field: 'dfje',
	                    // class:'col_debite',
	                    title: $.common.sprintf('<strong class="tit">贷方金额</strong><div class="money_unit"> <span>亿</span> <span>千</span> <span>百</span> <span>十</span> <span>万</span> <span>千</span> <span>百</span> <span>十</span> <span>元</span> <span>角</span> <span class="last">分</span></div>'),
	                    formatter: function(value, row, index) { 
	                        return '<div class="col_debite"><div class="cell_val debit_val">'+yantofan(row.dfje)+'</div></div>';
	                    },
	   				    footerFormatter:function (value) {
	   				    	var sumJe = 0;
	   				        for (var i in value) {
	   				        	sumJe += parseFloat(value[i].dfje);
	   				        }
	   				        return '<div class="col_debite"><div class="cell_val debit_val">'+yantofan(sumJe)+'</div></div>'
	   				    }
	                }/*,{
                        title: '辅助明细',
                        field: 'xh',
                        align: 'center',
                        formatter:function(value,row,index){  
                          var e;                             
                              e = '<a class="ui-btn tableed '+row.xh +'" onclick="view(\''+ index + '\')">+</a> ';                                  
                              return e;  
                          
                        } 
                    }*/]
		        };
		        $.table.init(options);
		    }); 
			initChildTable = function(index, row, $detail) {
				var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');

			 
	    	    $(childTable).bootstrapTable({
	    	        url: prefix + "/jtmxlist",
	    	        method: 'post',
	    	        sidePagination: "server",
	    	        theadClasses: "thead-blue",//设置thead-blue为表头样式
	    	        classes: "table table-bordered table-striped table-sm table-dark",
	    	        contentType: "application/x-www-form-urlencoded",
	    	        queryParams : {
	    	        	'pztxh':row.pztxh,
	    	        	'xh':row.xh
					},
	    	        columns: [{
						field : 'pzrq', 
						title : '凭证日期'
					},{
						field : 'pjh', 
						title : '票据号'
					},
					{
						field : 'dwbm', 
						title : '单位编码',
						align: 'center'
					},{
						field : 'dwmc', 
						title : '单位名称',
						align: 'center'
					}
					,{
						field : 'yskm', 
						title : '预算科目',
						align: 'center'
					}
					,{
						field : 'yskmmc', 
						title : '预算科目名称',
						align: 'center'
					}
					,{
						field : 'xmbm', 
						title : '项目编码',
						align: 'center'
					}
					,{
						field : 'xmmc', 
						title : '项目名称',
						align: 'center'
					},{
						field : 'jkr', 
						title : '缴款人名称',
						align: 'center'
					},
					{
						field : 'jfje', 
						title : '借方金额',
	                    align: 'right'
					},
					{
	                    field: 'dfje',
	                    title: '贷方金额',
	                    align: 'right' 
	                }]
	    	    });
	    	};
	    	
	    	/* 借方 */
			function yantofan(je) {
				var currencyDigits=String((Number(je)*100).toFixed(0));
				var MAXIMUM_NUMBER =  99999999999.99;
		   	    var MINMUM_NUMBER  = -99999999999.99;
		   	    //字体颜色
		
		   		if(currencyDigits==""||currencyDigits==null)currencyDigits="0";
		   		//去空格
		   		currencyDigits=cTrim(currencyDigits,0);
		   		
		   		if(!(/^(\+|-)?(0|[1-9]\d*)(\.\d*[1-9])?$/g.test(currencyDigits))){
		   			currencyDigits="";
		   		}
		   		currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters.
		   		if(currencyDigits!='0'){
		   			currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning.
		   		}
		   		/**
		   		 * 负数时候去掉符号,字体为红色
		   		 */
		   		if(Number(currencyDigits)<0){
		   			if(Number(currencyDigits) < MINMUM_NUMBER) {
		   				currencyDigits= "";
		   		    }
		   		    currencyDigits=currencyDigits.replace(/-/,"");
		   			span1='<span style="color:red;">';
		   			span2='</span>';
		   		}else{
		   		    currencyDigits=currencyDigits.replace(/\+/,"");
		   			if (Number(currencyDigits) > MAXIMUM_NUMBER) {
		   				currencyDigits= "";
		   			}
		   		}
		   		if (currencyDigits=='0'){
		   			currencyDigits= "";
		   		}
	    		return currencyDigits; 
			}
			/* function view(str){
			        var a=$('.tableed ').eq(str).html()
			        if(a=='+'){
			            $('.tableed ').eq(str).html('-')
			            $('#bootstrap-table').bootstrapTable('expandRow', str);
			        }
			        else{
			            $('.tableed ').eq(str).html('+')
			            $('#bootstrap-table').bootstrapTable('collapseRow', str);
			        }
			         event.stopPropagation();  
			    }
			*/
			 function DX(n) {
			        if (n == 0) {
			            return "零";
			        }
			        if (!/^(\+|-)?(0|[1-9]\d*)(\.\d+)?$/.test(n))
			            return "数据非法";
			        var unit = "仟佰拾亿仟佰拾万仟佰拾元角分", str = "";
			        n += "00";
			        var a = parseFloat(n);
			        if (a < 0) {
			            n = n.substr(1);
			        }
			        var p = n.indexOf('.');
			        if (p >= 0) {
			            n = n.substring(0, p) + n.substr(p + 1, 2);
			        }

			        unit = unit.substr(unit.length - n.length);

			        for (var i = 0; i < n.length; i++)
			            str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
			        if (a > 0) {
			            return str.replace(/零(仟|佰|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");

			        } else {

			            return "负" + str.replace(/零(仟|佰|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");
			        }
			    }
    </script>
</body>
</html>
